/*
 * WiiRemoteDiscoverer.java
 *
 *  Copyright (c) 2008 Corey Oliver and Anshul Kumaria
 *
 *  This file is part of Balls of Fury.
 *
 *  Balls of Fury is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Balls of Fury is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>
 *
 *
 */

/*
 * EDIT:  03/13/2008 - This is an example of how an edit performed to the class 
 * would appear.
 */
package ballsoffury.input;

import wiiremotej.WiiRemoteJ;
import wiiremotej.event.WiiRemoteDiscoveryListener;
import wiiremotej.event.WiiRemoteDiscoveredEvent;

/**
 * Allows the client to control the discovery of wiimotes and the events that 
 * occur when new wiimotes are discovered.
 *
 * @author Corey Oliver
 * @version $Revision:$ $Date:$
 */
public class WiiRemoteDiscoverer implements WiiRemoteDiscoveryListener {
    
    private WiiController wiiRemoteController;

    protected void discoverWiiRemotes(WiiController wiiRemoteController) {
        this.wiiRemoteController = wiiRemoteController;
        
        try {
            System.out.println("Finding remotes...");
            WiiRemoteJ.findRemotes(this);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    protected void stopDiscoverWiiRemotes() {
        WiiRemoteJ.stopFind();
        System.out.println("Wiimote discovery stopped.");
    }

    public synchronized void wiiRemoteDiscovered(WiiRemoteDiscoveredEvent evt) {
        System.out.println("Wiimote discovered!");
        WiiRemoteManager.addWiiRemote(evt.getWiiRemote(), wiiRemoteController);
    }

    public void findFinished(int numberFound) {
        System.out.println("Found " + numberFound + " remotes!");
    }
}
